
	layui.use(['form','layer','jquery','upload'],function(){
		var $ = layui.$,
		form = layui.form,
		layer = layui.layer,
		upload = layui.upload;
		
		//自定义校验规则
		form.verify({
			truename:function(value,item){//真实姓名
				if(!new RegExp(/^[\u4E00-\u9FA5\uf900-\ufa2d·s]{2,20}$/).test(value)){
					return '真实姓名填写有误';
				}
			},
			bankcardno:function(value){//银行卡号
				  var pattern = /^([1-9]{1})(\d{14}|\d{18})$/,
				  bankno = value.replace(/\s/g,'');
				  if(!pattern.test(bankno)){
				  	return '请正确输入银行卡号';
				  } 
			}
		});
		
		//上传图片
	  	var avatarSrc = $('#LAY_avatarSrc');
	  	upload.render({
		    url: urlHead + '/head/fileUploadBankCar'
		    ,elem: '#LAY_avatarUpload'
		    ,choose:function(obj){
		    	//预览银行卡图片
		    	obj.preview(function(index, file, result){
		    		$('#demo1').attr('src', result);
	
		    	});
		    }//上传接口请求成功，但文件不一定上传成功
		    ,done: function(res){	
		    	console.log(res);
		      	if(res.code == 0){
		        	avatarSrc.val(res.path);
		      	}else{
		       		layer.msg(res.msg, {icon: 5});
		      	}
		    }
	  	});
		
		//获取上个页面传过来的参数
	  	var loc = location.href;
		var n1 = loc.length;//地址的总长度
		var n2 = loc.indexOf("=");//取得=号的位置
		var uuid = decodeURI(loc.substr(n2+1, n1-n2));//从=号后面的内容
	  	console.log(uuid);
		
		form.on('submit(LAY-user-reg-submit2)',function(obj){
			var field = obj.field,			
			truename = field.truename,					//真实姓名
			identity = field.identity,					//身份证号
			bankcardno = field.bankcardno,				//银行卡号
			avatar = field.avatar;						//银行卡图片地址
			
			console.log(truename);
			console.log(identity);
			
			//确认银行卡号
			//测试数据6215593202018120900
			if(field.rebankcardno!==field.bankcardno){
				layer.msg('两次银行卡输入不一致');
				return false;
			}
			
			$.ajax({
				url:urlHead + "/user/doRegisterStep2",
				type:"GET",
				async:true,
				data:{"name":truename,"idNum":identity,"uuid":uuid},
				success:function(res){
					console.log(res);
					if(res.code == 0){
						$.ajax({
							type:"get",
							url:urlHead + "/user/doRegisterStep3",
							async:true,
							data:{
								"creditCardNum":bankcardno,
								"creditCardImage":avatar,
								"uuid":uuid
							},
							success:function(res){
								console.log(res);
								if(res.code==0){
									layer.msg('注册成功',{icon:1});
									location.href = "login_by_username_new.html";
								}else{
									layer.msg(res.msg,{icon:5});
								}
							},
							error:function(){
								layer.msg('注册失败',{icon:5});
							},
							dataType:'json'
						});
					}else{
						layer.msg(res.msg,{icon:5});
					}
				},
				error:function(){
					layer.msg('注册失败',{icon:5});
				},
				dataType:"json"
			});
			
			return false;
		});
	});